package net.viralpatel.struts2;

import java.sql.SQLException;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class AdminshortyoyakuAction extends ActionSupport{
	private String floor;
	private String roomType2;
	private int roomNumber;
	private String date;
	private String StartTime;
	private String EndTime;
	
	JDBCQuery jdbc;
	
	public String execute()
	{
		System.out.println(floor);
		System.out.println(StartTime);
		
		double cost;
		try {
			Map session = ActionContext.getContext().getSession();
			String username= session.get("username").toString();
			jdbc=new JDBCQuery();
			int price=jdbc.getPrice(roomType2);
			System.out.println(price);
			cost=jdbc.getHour(StartTime, EndTime)*price;
			System.out.println("cost:"+cost);
			int tmp_loai=1;			
			if(this.roomType2=="A")
				tmp_loai=1;
			else if(this.roomType2=="B")
				tmp_loai=1;
			else if(this.roomType2=="C")
				tmp_loai=1;
			else if(this.roomType2=="D")
				tmp_loai=1;
			else if(this.roomType2=="H")
				tmp_loai=2;
			else if(this.roomType2=="I")
				tmp_loai=2;
			else if(this.roomType2=="J")
				tmp_loai=2;			
			String roomId=tmp_loai+roomType2+floor+roomNumber;
			System.out.println("roomid"+roomId);
			int index=jdbc.getIndexYoyaku();
			index=index+1;
		String orderId=roomId+"_"+date+"_"+index;
			String sql="INSERT INTO yoyaku VALUES('0','"+orderId+"','"+username+"','"+roomId+"','"+date+"','"+StartTime+"','"+EndTime+"','0','0','0','"+cost+"')";
			jdbc.insertData(sql);
			
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			System.out.println("error");
			e.printStackTrace();
		} catch (SQLException e) {
			 System.out.println("error");
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
				
		return ActionSupport.SUCCESS;
	}

	public String getFloor() {
		return floor;
	}

	public void setFloor(String floor) {
		this.floor = floor;
	}

	public String getRoomType2() {
		return roomType2;
	}

	public void setRoomType2(String roomType2) {
		this.roomType2 = roomType2;
	}

	public int getRoomNumber() {
		return roomNumber;
	}

	public void setRoomNumber(int roomNumber) {
		this.roomNumber = roomNumber;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getStartTime() {
		return StartTime;
	}

	public void setStartTime(String startTime) {
		StartTime = startTime;
	}

	public String getEndTime() {
		return EndTime;
	}

	public void setEndTime(String endTime) {
		EndTime = endTime;
	}
	
	
	
}
